package demo000;
import java.util.Arrays;
public class ZuoYe2 {
	public static void main(String[] args){
		int[] a={5,3,7,2,9,8,1,4};
		quick(a,0,a.length-1);
	}
	private static void quick(int[] a, int l, int h) {
		if(l>=h){
			return;
		}
		int p =partition(a,l,h);
		quick(a,l,p-1);
		quick(a,p+1,h);
	}

	private static int partition(int[] a, int l, int h) {
		int pv=a[l];
		int i=l;
		int j=h;
		while(i<j){
			while(i<j && a[j]>pv){
				j--;
			}
			while(i<j && a[i]<=pv){
				i++;
			}
			swap(a,i,j);
		}
		swap(a,l,j);
		System.out.println(Arrays.toString(a));
		return j;
	}
	private static void swap(int[] a, int i, int j) {
		int t=a[i];
		a[i]=a[j];
		a[j]=t;
	}
}
